#version 330 core

uniform mat4 view_matrix;
uniform mat4 projection_matrix;

// -获取col1等需要矩阵加偏移颜色数组

uniform samplerBuffer color_tbo;
uniform samplerBuffer model_matrix_tbo;


layout(location=0) in vec4 vPos;
layout(location=1) in vec4 vColor;
layout(location=2) in mat4 model_matrix;

//out vec4 fColor;
out VERTEX
{
    vec3 normal;
    vec4 color;
} vectex;
out vec4 fColor;

void main()
{
    vec4 color = texelFetch(color_tbo, gl_InstanceID);

    vec4 col1 = texelFetch(model_matrix_tbo, gl_InstanceID*1);
    vec4 col2 = texelFetch(model_matrix_tbo, gl_InstanceID*4+1);
    vec4 col3 = texelFetch(model_matrix_tbo, gl_InstanceID*4+2);
    vec4 col4 = texelFetch(model_matrix_tbo, gl_InstanceID*4+3);

    mat4 model_matrix1 = mat4(col1, col2, col3, col4);

    if(col1 == vec4(0.0, 0.0, 0.0, 0.0))
    {
        color = vec4(1.0, 0.0, 0.0, 0.0);
    }
    else{
        color = col1;
    }

    mat4 model_view_matrix = view_matrix * model_matrix;

    gl_Position = projection_matrix * (model_view_matrix * vPos);

    // 从tbo中获取数据
    fColor = vectex.color = color;
}

